package cnsatmsmart.automation.mmi.model.data.TSafe;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;

/**
 * @author SIK - PTIK, BPPT
 **/

public class Trajectory {   //based on TSafe
    /* atribut - atribut yang dimiliki oleh kelas Trajectory */
        private List points;    //senarai yang berisi catatan Point4D dari object

    /* constructor - user defined ctor, no default ctor */
        // <editor-fold defaultstate="collapsed" desc="ctor">
        /*
         * @param = atribut
         */
        public Trajectory () {
            this.points = new LinkedList();
        }
        public Trajectory (Trajectory t) {
            this.points = new LinkedList(t.getPoints());
        }
        // </editor-fold>

    /* getter */
        public List getPoints () {
            /* mengembalikan nilai dari atribut points */
            return (this.points);
        }

    /* method - method yang dimiliki oleh kelas Trajectory */
        public boolean isEmpty () {
            return (this.points.isEmpty());
        }
        public void addPoint (Point4D p) {
            this.points.add(p);
        }
        public Point4D firstPoint () {
            if (this.isEmpty()) {
                throw new NoSuchElementException("empty trajectory");
            } else {
                return ((Point4D)this.points.get(0));
            }
        }
        public Point4D lastPoint () {
            if (this.isEmpty()) {
                throw new NoSuchElementException("empty trajectory");
            } else {
                return ((Point4D)this.points.get(this.points.size() - 1));
            }
        }
        public List pointsList () {
            return (Collections.unmodifiableList(this.points));
        }
        public Iterator pointsIterator () {
            return (this.points.iterator());
        }

    @Override
    public String toString () {
        StringBuilder strBuildr = new StringBuilder("[");
        Iterator pointsIter = this.pointsIterator();
        while (pointsIter.hasNext()) {
            strBuildr.append(pointsIter.next());
            if (pointsIter.hasNext()) {
                strBuildr.append(", ");
            }
        }
        strBuildr.append("]");

        return (strBuildr.toString());
    }
}
